package com.jiepos.mpos.biz.operationlog.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.jiepos.mpos.biz.appInfM.service.OrganizationService;
import com.jiepos.mpos.biz.operationlog.service.SmsCodeFlowService;
import com.jiepos.mpos.common.entity.App_Rand_InfEntity;
import com.jiepos.mpos.core.controller.BaseController;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 短信验证码流水管理
 * @ProjectName:  [mpos] 
 * @Package com.jiepos.mpos.biz.operationlog.controller 
 * @author 张磊
 * @version 1.0
 * @since 2017年10月9日 下午2:25:47
 * @history（历次修订内容、修订人、修订时间等）
 * @UpdateRemark [说明本次修改内容]
 * @Copyright (c) 2017 江苏杰博实信息技术有限公司
 */
@Controller
@RequestMapping("smsCodeFlow")
public class SmsCodeFlowController extends BaseController {
	/** 导出文件名称*/
	private static String EXCEL_SMSCODE_NAME = "短信验证码流水.xls";
	@Autowired
	private SmsCodeFlowService smsCodeFlowService;
	@Autowired
	private OrganizationService organizationService;
	
	/**
	 * 获取短信验证码流水页面
	 * @param pagination
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping("/getSmsCodeFlowList.do")
	public ModelAndView getSmsCodeFlowList(Pagination pagination, HttpServletRequest request,HttpServletResponse response){
		ModelAndView model = new ModelAndView("/module/operationlog/smscodelog/smscodelog_list");
		model.addObject("appInses", organizationService.getAllAppIns(request));
		return super.getDetail(request, response, model);
	}
	
	/**
	 * 获取短信验证码流水Json
	 * @param request
	 * @param response
	 * @param pagination
	 * @param app_Rand_InfEntity
	 * @return
	 */
	@RequestMapping("/getSmsCodeFlowListJson.do")
	public Map getSmsCodeFlowListJson(HttpServletRequest request,HttpServletResponse response,Pagination pagination,App_Rand_InfEntity app_Rand_InfEntity){
		return smsCodeFlowService.getSmsCodeFlowList(pagination,request,app_Rand_InfEntity);
	}

	/**
	 * 短信验证码导出
	 * @param request
	 * @param response
	 * @param pagination
	 * @param appRandInfEntity
	 */
	@RequestMapping("/exportSmsCodeFlowList.do")
	public void exportSmsCodeFlowList(HttpServletRequest request, HttpServletResponse response, Pagination pagination,
									  App_Rand_InfEntity appRandInfEntity){
		super.clearCookie(request, response);
		String msg = smsCodeFlowService.exportSmsCodeFlowList(request, EXCEL_SMSCODE_NAME,appRandInfEntity);
		if (StringUtils.isBlank(msg)) {
			super.setFileParam(request, response, EXCEL_SMSCODE_NAME);
		} else {
			super.setErrorFileParam(request, response, msg);
		}
	}
}
